package cn.agiledata.bank.audit.logic;

import cn.agiledata.bank.common.bean.IntEnum;

/**
 * 审核状态
 * 
 * @author 马贤波
 * 
 */
public class AuditStatus extends IntEnum {
    /**
     * 审核状态：未知
     */
    public static final AuditStatus STATUS_UNKNOWN = new AuditStatus(-99);

    /**
     * 审核状态：已取消
     */
    public static final AuditStatus STATUS_CANCEL = new AuditStatus(-98);

    /**
     * 审核状态：初始状态
     */
    public static final AuditStatus STATUS_PRIMARY = new AuditStatus(-1);

    /**
     * 审核状态：被拒绝
     */
    public static final AuditStatus STATUS_REJECTED = new AuditStatus(0);

    /**
     * 审核状态：已提交
     */
    public static final AuditStatus STATUS_SUBMITTED = new AuditStatus(1);

    /**
     * 审核状态：终审完毕
     */
    public static final AuditStatus STATUS_FINAL = new AuditStatus(99);

    private AuditStatus(int value) {
        super(value);
    }

    public static AuditStatus getAuditStatus(int value) {
        if (value < STATUS_CANCEL.getValue())
            return STATUS_UNKNOWN;
        if (value == STATUS_CANCEL.getValue())
            return STATUS_CANCEL;
        if (value == STATUS_PRIMARY.getValue())
            return STATUS_PRIMARY;
        if (value == STATUS_REJECTED.getValue())
            return STATUS_REJECTED;
        if (value == STATUS_SUBMITTED.getValue())
            return STATUS_SUBMITTED;
        if (value == STATUS_FINAL.getValue())
            return STATUS_FINAL;
        return new AuditStatus(value);
    }

    public static AuditStatus getAuditStatus(AuditLevel auditLevel) {
        return getAuditStatus(auditLevel.getValue());
    }

    /**
     * 判断指定审核级别是否与本审核状态相对应
     * 
     * @param auditLevel
     *            审核级别
     * @return true if 审核级别与本审核状态相对应, otherwise false
     */
    public boolean isAccordant(AuditLevel auditLevel) {
        return this.getValue() == auditLevel.getValue();
    }

    /**
     * 
     * @return 当前审核状态的下一审核状态
     */
    public AuditStatus nextAuditStatus() {
        if (this == STATUS_PRIMARY || this == STATUS_REJECTED)
            return STATUS_SUBMITTED;
        if (this == STATUS_FINAL)
            return STATUS_FINAL;
        if (this == STATUS_CANCEL)
            return STATUS_CANCEL;
        if (this == STATUS_UNKNOWN)
            return STATUS_UNKNOWN;
        return new AuditStatus(this.getValue() + 1);
    }

}